﻿#pragma once


#include <QDialog>
#include <QPushButton>
#include "QListView"
#include "QStringListModel"
#include "QFileDialog"
#include "QMessageBox"
#include "QApplication"
#include "QVBoxLayout"
#include <QDesktopWidget>
#include <QLibrary>
#include <QApplication>
#include <QLabel>
#include <QComboBox>
#include "QListView"
#include "QStringListModel"
#include "QLineEdit"
#include "QSpinBox"
#include "QRadioButton"
#include <QSettings>

#include "commonfunction.h"

#include "halcon_opencv.h"

using namespace std;

#include "qt_graphics_view_image.h"


#include "function_dl_3.h"

#include "function_blob_match.h"
#include "function_detection_character.h"
#include "function_measureElectrode.h"
//#include "function_detectionElectrode.h"

//#include "function_detectionElectrode_rect.h"
//#include "function_detectionHSVh"
#include "function_detectionGRAY.h"
#include "function_detectionThreshold.h"
#include <QSettings>
#include <QStandardItemModel>

class Function:public QDialog
{
    Q_OBJECT
public:
    QSettings* m_qsettings;
	int m_camera_index = 0;


    QPushButton* m_pushbutton_open_model_image;

    QPushButton* m_pushbutton_save_model_image;
    QString m_model_image_path = "model.png";

//    QLabel* m_qlabel_row1;
//    QSpinBox* m_qspinbox_row1;

//    QLabel* m_qlabel_row2;
//    QSpinBox* m_qspinbox_row2;

//    QLabel* m_qlabel_column1;
//    QSpinBox* m_qspinbox_column1;

//    QLabel* m_qlabel_column2;
//    QSpinBox* m_qspinbox_column2;

//    cv::Rect m_roi_rect;
//    QPushButton* m_pushbutton_set_roi;


    FunctionBlobMatch*    m_function_blob_match;
    MeasureElectrode*     m_measure_electrode;
    DetectionThreshold*   m_detection_electrode_rect_left;
    DetectionThreshold*   m_detection_electrode_rect_right;
    DetectionCharacter*   m_detection_character;
    DetectionThreshold*         m_detection_hsv;

    DetectionThreshold*         m_detection_rgb1;
    DetectionThreshold*         m_detection_rgb2;
    DetectionThreshold*         m_detection_rgb3;
    DetectionThreshold*         m_detection_rgb4;
    DetectionThreshold*         m_detection_rgb5;

    Detection_dl_3*       m_function_dl_3;

    Mat m_image ;
    QString m_path_para = "para.json";
    QString m_section   = "";

    MyQGraphicsView* m_view ;

    QPushButton* m_pushbutton_load_image;
    QPushButton* m_pushbutton_load_dir;

	QPushButton* m_pushbutton_load_ok_dir;
	QPushButton* m_pushbutton_load_ng_dir;

    QListView* m_listview;
    QStringListModel* m_listview_model;
	vector<Mat> m_save_ok_vector_mat;
	vector<Mat> m_save_ng_vector_mat;

	
    QPushButton* m_pushbutton_blob_math;
    Mat image_out;
    QComboBox* m_qcombobox_unuse_use;
    int m_unuse_use_function = 0;


    QPushButton* m_pushbutton_measure_electrode;
    QComboBox* m_qcombobox_unuse_use_measure_electrode;
    int m_unuse_use_measure_electrode = 0;

    QPushButton* m_pushbutton_detection_electrode_left;
    QComboBox* m_qcombobox_unuse_use_detection_electrode_left;
    int m_unuse_use_detection_electrode_left = 0;

	QPushButton* m_pushbutton_detection_electrode_right;
	QComboBox* m_qcombobox_unuse_use_detection_electrode_right;
	int m_unuse_use_detection_electrode_right = 0;

    
    QPushButton* m_pushbutton_detection_charater;
    QComboBox* m_qcombobox_unuse_use_detection_charater;
    int m_unuse_use_detection_charater = 0;

    QPushButton* m_pushbutton_detection_hsv;
    QComboBox* m_qcombobox_unuse_use_detection_hsv;
    int m_unuse_use_detection_hsv = 0;

    QPushButton* m_pushbutton_detection_rgb1;
    QComboBox* m_qcombobox_unuse_use_detection_rgb1;
    int m_unuse_use_detection_rgb1 = 0;

    QPushButton* m_pushbutton_detection_rgb2;
    QComboBox* m_qcombobox_unuse_use_detection_rgb2;
    int m_unuse_use_detection_rgb2 = 0;

    QPushButton* m_pushbutton_detection_rgb3;
    QComboBox* m_qcombobox_unuse_use_detection_rgb3;
    int m_unuse_use_detection_rgb3 = 0;

    QPushButton* m_pushbutton_detection_rgb4;
    QComboBox* m_qcombobox_unuse_use_detection_rgb4;
    int m_unuse_use_detection_rgb4 = 0;

    QPushButton* m_pushbutton_detection_rgb5;
    QComboBox* m_qcombobox_unuse_use_detection_rgb5;
    int m_unuse_use_detection_rgb5 = 0;

    QPushButton* m_pushbutton_dl_3;
    QComboBox* m_qcombobox_unuse_use_dl_3;
    int m_unuse_use_dl_3 = 0;

    DetectionGRAY*         m_detection_gray;
    QPushButton* m_pushbutton_detection_gray;
    QComboBox* m_qcombobox_unuse_use_detection_gray;
    int m_unuse_use_detection_gray = 0;

    QComboBox* m_qcombobox_save_wrong;
    int m_save_wrong = 0;

    QComboBox* m_qcombobox_save_right;
    int m_save_right = 0;

//    QComboBox* m_qcombobox_save_roi_wrong;
//    int m_save_roi_wrong = 0;

//    QComboBox* m_qcombobox_save_roi_right;
//    int m_save_roi_right = 0;

//    QLabel * m_qlabel_save_jpg_png;
//    QComboBox* m_qcombobox_save_jpg_png;
//    int m_save_jpg_png= 0;


//    QComboBox* m_qcombobox_save_wrong_label;
//    int m_save_wrong_label = 0;

//    QComboBox* m_qcombobox_save_right_label;
//    int m_save_right_label = 0;

    QPushButton* m_pushbutton_save_load_image;
	QPushButton* m_pushbutton_show_orign_image;
    QPushButton* m_pushbutton_detection;
    QPushButton* m_pushbutton_save_parameter;
    QPushButton* m_pushbutton_return;

	//主界面 表格显示
	
	QTableView *m_show_table=nullptr;
	QStandardItemModel* m_show_table_data = nullptr;


    Mat m_image_show;

    int m_result;


public:
    explicit Function(QDialog* parent, QString path_in, int camera_index);



    bool detection(HObject image_in, QString& message);



    void detectionImage();

    void draw(Mat image_in, Mat& image_out);

    void listViewClick(const QModelIndex& model_index);

    void loadParameter(QString path_in, QString section);

    void saveParameter();
    void saveImage();
};
#pragma execution_character_set("utf-8")
